package com.itzhoun.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author 周楠
 * @Date 2022/07/19/下午 10:24
 */
@Configuration
public class DirectRabbitConfig {

    /**
     * name  队列名
     * durable 是否持久化,默认为false, 持久化队列会被永远储存在磁盘上，当消息代理后重启仍然存在
     * exclusive 默认为false,只能被当前的连接使用，当前连接关闭后队列会被删除，优先级高于durable
     * autoDelete 默认为false, 没有生产者或者消费者  队列会被删除
     * @return
     */
    @Bean
    public Queue directQueue(){
        return new Queue("directQueue", true, false,false);
    }

    /**
     * 创建直连交换机
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("directExchange", true, false);
    }


    /**
     * 绑定交换机
     * @return
     */
    @Bean
    Binding bindingDirectExchange(){
        return BindingBuilder.bind(directQueue()).to(directExchange()).with("directRouting");
    }
}
